package other;

import java.util.Arrays;
import java.util.List;

public class combine {
    static int []L={1,2,3,4,8};
    static int []M={2,5,6,10,12};
    public static int[] combine(int[] L, int[] M){
        int L_index=0,M_index=0,C_index=0;
        int []C=new int[L.length+M.length];
        while(L_index!=L.length && M_index!=M.length ){
            int A=L[L_index];
            int B=M[M_index];
            if( A<B ){
                L_index++;
                C[C_index++]=A;
            }else {
                M_index++;
                C[C_index++]=B;
            }
        }
        while(L_index!=L.length)
            C[C_index++]=L[L_index++];
        while(M_index!=M.length)
            C[C_index++]=M[M_index++];
        return C;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(combine(L, M)));
    }
}
